package com.igeek.clud_system.controller;


import com.igeek.clud_system.entity.Activity;
import com.igeek.clud_system.entity.ActivityAttend;
import com.igeek.clud_system.entity.Club;
import com.igeek.clud_system.service.PersonalCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PersonalController {
    @Autowired
    private PersonalCenterService personalCenter;

    /**
     *  查询登录用户的社团
     * @return
     */
    @GetMapping("club/myclub")
    public List<Club> myClub(){
      return   personalCenter.myClub();
    }

    /**
     * 查询登录用户的活动
     * @return
     */
    @GetMapping("activity/myactivity")
    public List<Activity> myActivity(){
        return   personalCenter.myActivity();
    }

    /**
     *  更新活动状态(签到)
     * @param activityId
     */
    @PostMapping("activity/sign/{activityId}/{studentId}")
    public void updateActivityAttend(@PathVariable("activityId") Integer activityId ,@PathVariable("studentId") Integer studentId){
        ActivityAttend activityAttend = new ActivityAttend();
        activityAttend.setActivityId(activityId);
        activityAttend.setStudentId(studentId);
        activityAttend.setStatus(2);
        personalCenter.updateActivityAttend(activityAttend);
    }
    /**
     * 根据活动ID获取验证码
     * @param activityId 活动ID
     * @return 验证码
     */
    @GetMapping("activity/verificationCode/{activityId}")
    public Map<String, String> getVerificationCode(@PathVariable("activityId") Integer activityId) {
        Activity activity = personalCenter.getVerificationCode(activityId);
        if (activity != null) {
            Map<String, String> response = new HashMap<>();
            response.put("code", activity.getActivityCode());
            return response;
        } else {
            return null;
        }
    }
}
